import numpy as np
from keras.layers import Dense, Dropout
from keras.models import Sequential
import matplotlib.pyplot as plt

# 生成数据
x_train = np.random.random((1000, 20))
y_train = np.random.randint(2, size=(1000, 1))
x_test = np.random.random((100, 20))
y_test = np.random.randint(2, size=(100, 1))

model = Sequential()
model.add(Dense(64, input_dim=20, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))

model.compile(loss='binary_crossentropy',
              optimizer='rmsprop',
              metrics=['accuracy'])
epoch = 20
model.fit(x_train, y_train, epochs=20, batch_size=128)
score = model.evaluate(x_test, y_test, batch_size=128)

history = model.predict(x_train)
print(np.shape(history))

# print(history)
x = range(1000)
plt.plot(x[:5], history[:5,])
plt.plot(x[:5], x_train[:5,])
plt.show()